<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>

        let word = 'wc , 正则真tm简单 , Wc  Tm' ;

        // let reg = /wc|tm/ig ;

        // console.log(word.replace(reg , '**'));


       

        const filterWord = (word , arr) => {
            // 把敏感词存入数组
            arr = arr || ['wc' , 'tm' , 'nm'];
            // 数组转字符串
            // 'wc|tm|nm'
            const str = arr.join('|');
            // console.log(str);
            const reg = new RegExp(str , 'ig');
            return word.replace(reg , '**') ;
        }


        console.log(filterWord(word, ['tm']) );

    </script>
</body>
</html>